--TEST--
bool MySQLndUhConnection::query(resource $connection, string $query)
--SKIPIF--
<?php
require_once('skipif.inc');
if (!extension_loaded("mysql"))
	die("skip For simplicity this test depends on mysql, you should enable mysql, mysqli and pdo_mysql for testing.");

if (!extension_loaded("pdo"))
	die("skip For simplicity this test depends on pdo_mysql, you should enable mysql, mysqli and pdo_mysql for testing.");
?>
--FILE--
<?php
	require_once('config.inc');

	function mysqli_do_query($mysqli, $query) {
		if (!$res = $mysqli->query($query)) {
			printf("[%d] '%s'\n", $mysqli->errno, $mysqli->error);
			return;
		}

		printf("mysqli query = %s\n", $query);
		$rowno = 1;
		while ($row = $res->fetch_row()) {
			printf("row = %d\n", $rowno++);
			for ($i = 0; $i < count($row); $i++) {
				printf("\t%03d = %s\n", $i, var_export($row[$i], true));
			}
		}
		$res->close();
	}

	function mysql_do_query($mysql, $query) {
		if (!$res = mysql_query($query, $mysql)) {
			printf("[%d] '%s'\n", mysql_errno($mysql), mysql_error($mysql));
			return;
		}

		printf("mysql query = %s\n", $query);
		$rowno = 1;
		while ($row = mysql_fetch_row($res)) {
			printf("row = %d\n", $rowno++);
			for ($i = 0; $i < count($row); $i++) {
				printf("\t%03d = %s\n", $i, var_export($row[$i], true));
			}
		}

		mysql_free_result($res);
	}

	function pdo_do_query($pdo, $query) {
		if (!$res = $pdo->query($query)) {
			printf("%s\n", $pdo->errorCode());
			return;
		}

		printf("pdo query = %s\n", $query);
		$rowno = 1;
		while ($row = $res->fetch(PDO::FETCH_NUM)) {
			printf("row = %d\n", $rowno++);
			for ($i = 0; $i < count($row); $i++) {
				printf("\t%03d = %s\n", $i, var_export($row[$i], true));
			}
		}
	}

	class proxy extends MySQLndUhConnection {
		public function query($res, $query) {
			printf("%s(%s, %s)\n", __METHOD__, var_export($res, true), var_export($query, true));

			$query = "SELECT 'query rewritten by user proxy'";
			$ret = parent::query($res, $query);

			printf("\tret = %s\n", var_export($ret, true));
			return $ret;
		}
	}

	class proxy2 extends MySQLndUhConnection {
		public function query($res, $query) {
			return $query;
		}
	}

	$mysqli = mysqlnd_uh_test\connect::mysqli();
	$mysql = mysqlnd_uh_test\connect::mysql();
	$pdo = mysqlnd_uh_test\connect::pdo();

	mysqli_do_query($mysqli, "SELECT 'test with mysqli but without proxy'");
	mysql_do_query($mysql, "SELECT 'test with mysql but without proxy'");

	mysqlnd_uh_set_connection_proxy(new proxy());

	mysqli_do_query($mysqli, "SELECT 'proxy test with mysqli'");
	mysql_do_query($mysql, "SELECT 'proxy test with mysql'");

	mysqlnd_uh_set_connection_proxy(new proxy2());
	mysqli_do_query($mysqli, "SELECT 'proxy test with mysqli'");
	mysql_do_query($mysql, "SELECT 'proxy test with mysql'");

	print "done!";
?>
--EXPECTF--
mysqli query = SELECT 'test with mysqli but without proxy'
row = 1
	000 = 'test with mysqli but without proxy'
mysql query = SELECT 'test with mysql but without proxy'
row = 1
	000 = 'test with mysql but without proxy'
proxy::query(NULL, 'SELECT \'proxy test with mysqli\'')
	ret = true
mysqli query = SELECT 'proxy test with mysqli'
row = 1
	000 = 'query rewritten by user proxy'
proxy::query(NULL, 'SELECT \'proxy test with mysql\'')
	ret = true
mysql query = SELECT 'proxy test with mysql'
row = 1
	000 = 'query rewritten by user proxy'

Warning: mysqli::query(): (MySQLnd User Handler) The method MySQLndUhConnection::query() did not return a boolean value as it should in %s on line %d

Warning: mysqli::query(): (00000/0):  in %s on line %d
[0] ''

Warning: mysql_query(): (MySQLnd User Handler) The method MySQLndUhConnection::query() did not return a boolean value as it should in %s on line %d

Warning: mysql_query(): Unable to save result set in %s on line %d
[0] ''
done!